//
//  XMHasGuardTipView.m
//  XunMi
//
//  Created by MacBook on 2024/3/27.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMHasGuardTipView.h"

@implementation XMHasGuardTipView

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.priceBtn setImagePosition:XMImagePositionLeft spacing:5];
    [self.priceBtn setTitle:kGlobalVariables.appConfig.chat.user_guard_golds.stringValue forState:UIControlStateNormal];
    
    NSString *str = kStringFormat(@"持续+亲密度：文字、语音、视频聊天 以及赠送礼物等\n一次性+亲密度：开启守护+%@°亲密度", kGlobalVariables.appConfig.chat.guardian_intimacy);
    // 创建NSMutableAttributedString，并设置文本内容和属性
    NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:str];
    // 创建NSMutableParagraphStyle，并设置行高
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.alignment = NSTextAlignmentLeft;
    paragraphStyle.lineSpacing = 8; // 设置行高为10个点
    // 将行高属性添加到文本属性中
    [attributedText addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedText.length)];
    [attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFangSC-Medium" size:12] range:[str rangeOfString:@"持续+亲密度："]];
    [attributedText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFangSC-Medium" size:12] range:[str rangeOfString:@"一次性+亲密度："]];

    self.tipLa.attributedText = attributedText;
    [self.tipLa sizeToFit];
    
}

- (IBAction)guardAction:(UIButton *)sender {
    if (self.guardBlock) {
        self.guardBlock();
    }
}

- (IBAction)closeAct:(UIButton *)sender {
    if (self.closeBlock) {
        self.closeBlock();
    }
}

- (void)setIntimacyStr:(NSString *)intimacyStr {
    _intimacyStr = intimacyStr;
    NSString *str = kStringFormat(@"当前亲密度为%@°，如亲密度低于%@°，彼此不再显示守护。", intimacyStr, kGlobalVariables.appConfig.chat.guardian_intimacy);     // 创建NSMutableAttributedString，并设置文本内容和属性
    NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:str];
    // 创建NSMutableParagraphStyle，并设置行高
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.alignment = NSTextAlignmentLeft;
    paragraphStyle.lineSpacing = 8; // 设置行高为10个点
    // 将行高属性添加到文本属性中
    [attributedText addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedText.length)];
    self.descLa.attributedText = attributedText;
    [self.descLa sizeToFit];
}

@end
